# -*- coding: utf-8 -*-

import urllib2

import cookielib


if __name__ == '__main__':
    test_rul = "http://www.baidu.com/"
    response = urllib2.urlopen(test_rul)
    print response.getcode()
    print response.read()
    print "-----------------"
    # 可以添加用户名密码的
    request = urllib2.Request(test_rul)
    # request.add_header()
    # request.add_data()
    response2 = urllib2.urlopen(request)
    print response2.read()
    print "======================="
    cookie = cookielib.CookieJar()
    handler=urllib2.HTTPCookieProcessor(cookie)
    opener = urllib2.build_opener(handler)
    response3 = opener.open('http://www.baidu.com')
    print response3.read()
